const express = require('express')
const router = express.Router()

const apiAdmin = require('./apiAdmin')

const { lowdb } = require('./../db/lowdb')
const config = require('./../config')
const API_VERSION = config.API_VERSION // 接口版本

const init = lowdb
  .read()
  .get('init')
  .value()
console.log(init);
if (init.is_success) {
  router.use(`/api-admin/${API_VERSION}`, apiAdmin)
} else {
  console.log('项目还未初始化，请初始化后再继续进行当前操作......')
  console.log(
    `运行npm run init 进入初始化，端口号为：${config.initPort}`
  )
  router.use('*', async (req, res) => {
    res.send(`项目还未初始化，请初始化后再进行继续操作,运行npm run init 进入初始化，端口号为：${config.initPort}`)
  })
}
module.exports = router
